package com.chmingx.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chmingx.edu.entity.Teacher;
import com.chmingx.edu.mapper.TeacherMapper;
import com.chmingx.edu.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chmingx.edu.vo.TeacherQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author chmingx
 * @since 2021-09-20
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public Page<Teacher> query(TeacherQuery teacherQuery) {
        Page<Teacher> page = new Page<>(teacherQuery.getCurrentPage(), teacherQuery.getPageSize());
        // 多条件组合查询，使用wrapper，要求这些项不能为空，或者使用mybatis的动态sql，-> mapper -> xml 在xml中写动态sql, 允许有空的项目
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.like("name", teacherQuery.getName())
                .eq("level", teacherQuery.getLevel())
                .gt("gmt_create", teacherQuery.getBegin())
                .lt("gmt_modified", teacherQuery.getEnd());
        page(page, wrapper);
        return page;
    }
}
